package com.kdtech.analyse.NewsPaper;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.HtmlCleaner;
import com.kdtech.utils.StringUtils;
import com.kdtech.analyse.AnalyseNews;

/**
 * http://lsrb.newssc.org 乐山日报<br>
 * http://ybwb.newssc.org 宜宾晚报<br>
 * http://myrb.newssc.org 绵阳日报<br>
 * http://pzhrb.newssc.org 攀枝花日报<br>
 * http://sckjb.newssc.org/html/2012-11/30/node_451.htm 四川科技报<br>
 * http://lswb.newssc.org/html/2012-12/04/node_56.htm	三江都市报<br>
 * http://cjb.newssc.org/html/2012-12/04/node_82.htm	经理日报<br>
 * http://222.209.217.193:8088/html/2014-02/13/node_3.htm	四川政协报<br>
 * http://wxb.newssc.org/html/2012-11/29/node_460.htm	晚霞报<br>
 * @author abc
 *
 */
public class NewsscNewsPaperAnalyse implements AnalyseNews {

	
	
	public boolean isDetailPage(String url) {
		boolean bRet = false;
		String[] regex = {
				"http://(xnsb|msrb|sckjb|cjb|cdrb|scgrrb).newssc.org/html/[0-9]{4}-[0-9]{2}/[0-9]{2}/content_[0-9]*.htm",
				
				};
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {		
		NewsMeta newspaper = new NewsMeta();
				
		String html = urlMeta.getHtml();
		String url = urlMeta.getUrl();		
						
		newspaper.setUrl(url);		
		String title = null;
		String content = null;
		Long date = null;
		Document doc = Jsoup.parse(html);
		
		title =title =doc.select("td.font01").text();
		
		content =HtmlCleaner.getContentHtml(url,doc.select("founder-content"));
		
		
		date=DateUtils.matchDate(url);
		
		newspaper.setTitle(StringUtils.trimSpace(title));
		newspaper.setContent(StringUtils.trimSpace(content));
		newspaper.setDate(date);
		return newspaper;
	}
	
	
	public boolean isTaskPage(String url) {
		boolean bRet = false;
		String[] regex = {
				
				"http://(xnsb|msrb|sckjb|cjb|cdrb|scgrrb).newssc.org/html/[0-9]{4}-[0-9]{2}/[0-9]{2}/node_[0-9]*.htm"
				
				};
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}
	
	
}
